package webapp;

import java.util.ArrayList;
import java.util.List;

import mda.type.IAnyInterface;
import mda.type.IDtoType;
import mda.type.IEntityType;
import mda.type.IServiceType;
import flca.mda.codegen.data.ITemplate;
import flca.mda.codegen.data.Template;
import flca.mda.codegen.data.TemplateMergeStrategy;

public class DojoConstants implements TemplatesConstBase  {
	
	public static final String CARTRIDGE_NAME = "webapp-dojo";
	
	protected static final String Frontend = LE + WebappConstants.FRONTEND_DOJO + RI + "/js";
	
	public Tid[] getTemplates() {
		return Tid.getDojoTemplates();
	}

	private static List<ITemplate> allTemplates;
	
	public DojoConstants() {
		super();
		if (allTemplates == null) {
			allTemplates = makeTemplates();
		}
	}

	@Override
	public List<ITemplate> getAllTemplates() {
		return allTemplates;
	}

	public List<ITemplate> makeTemplates() {
		List<ITemplate> result = new ArrayList<ITemplate>();

		result.add(makeTemplate_DOJO_ENTITY());
		result.add(makeTemplate_DOJO_DTO());
		result.add(makeTemplate_DOJO_ENUM());
		result.add(makeTemplate_DOJO_ENTITY_DETAIL());
		result.add(makeTemplate_DOJO_ENTITY_BROWSE());
		result.add(makeTemplate_DOJO_ENTITY_SEARCH());
		result.add(makeTemplate_DOJO_ENTITY_CONTROLLER());
		result.add(makeTemplate_DOJO_SERVICE());
		result.add(makeTemplate_DOJO_SERVICE_MOCK());
		result.add(makeTemplate_DOJO_SERVICE_IMPL());
		result.add(makeTemplate_DOJO_APP_CONSTANTS());
		result.add(makeTemplate_DOJO_WIDGET_HTML());
		result.add(makeTemplate_DOJO_WIDGET_JS());
		
		return result;
	}

	private ITemplate makeTemplate_DOJO_ENTITY() {
		Template r = new Template();
		r.setName(Tid.DOJO_ENTITY.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoEntity.class.getName());
		r.setJetPath("/frontend/dojo/Entity.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_DTO() {
		Template r = new Template();
		r.setName(Tid.DOJO_DTO.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoDto.class.getName());
		r.setJetPath("/frontend/dojo/Dto.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_ENUM() {
		Template r = new Template();
		r.setName(Tid.DOJO_ENUM.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoEnum.class.getName());
		r.setJetPath("/frontend/dojo/Enum.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {Enum.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_ENTITY_DETAIL() {
		Template r = new Template();
		r.setName(Tid.DOJO_ENTITY_DETAIL.name());
		r.setPackage("<%=PACKAGE%>.view");
		r.setClassname("<%=CLASSNAME%>DetailForm");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoDetailForm.class.getName());
		r.setJetPath("/frontend/dojo/DetailForm.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_ENTITY_BROWSE() {
		Template r = new Template();
		r.setName(Tid.DOJO_ENTITY_BROWSE.name());
		r.setPackage("<%=PACKAGE%>.view");
		r.setClassname("<%=CLASSNAME%>BrowseForm");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoBrowseForm.class.getName());
		r.setJetPath("/frontend/dojo/BrowseForm.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_ENTITY_SEARCH() {
		Template r = new Template();
		r.setName(Tid.DOJO_ENTITY_SEARCH.name());
		r.setPackage("<%=PACKAGE%>.view");
		r.setClassname("<%=CLASSNAME%>SearchForm");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoSearchForm.class.getName());
		r.setJetPath("/frontend/dojo/SearchForm.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_ENTITY_CONTROLLER() {
		Template r = new Template();
		r.setName(Tid.DOJO_ENTITY_CONTROLLER.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Controller");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoEntityController.class.getName());
		r.setJetPath("/frontend/dojo/EntityController.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_SERVICE() {
		Template r = new Template();
		r.setName(Tid.DOJO_SERVICE.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoService.class.getName());
		r.setJetPath("/frontend/dojo/Service.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_SERVICE_MOCK() {
		Template r = new Template();
		r.setName(Tid.DOJO_SERVICE_MOCK.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Mock");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoServiceMock.class.getName());
		r.setJetPath("/frontend/dojo/ServiceMock.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_SERVICE_IMPL() {
		Template r = new Template();
		r.setName(Tid.DOJO_SERVICE_IMPL.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Impl");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoServiceImpl.class.getName());
		r.setJetPath("/frontend/dojo/ServiceImpl.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_APP_CONSTANTS() {
		Template r = new Template();
		r.setName(Tid.DOJO_APP_CONSTANTS.name());
		r.setPackage("<%=App-package%>");
		r.setClassname("<%=App-name%>Constants");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoAppConstants.class.getName());
		r.setJetPath("/frontend/dojo/AppConstants.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IAnyInterface.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_WIDGET_HTML() {
		Template r = new Template();
		r.setName(Tid.DOJO_WIDGET_HTML.name());
		r.setPackage("<%=PACKAGE%>.widget");
		r.setClassname("<%=CLASSNAME%>Widget");
		r.setTargetDir(Frontend);
		r.setFileExtension(".html");
		r.setGeneratorFqn(frontend.dojo.DojoWidgetHtml.class.getName());
		r.setJetPath("/frontend/dojo/widget-html.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_DOJO_WIDGET_JS() {
		Template r = new Template();
		r.setName(Tid.DOJO_WIDGET_JS.name());
		r.setPackage("<%=PACKAGE%>.widget");
		r.setClassname("<%=CLASSNAME%>Widget");
		r.setTargetDir(Frontend);
		r.setFileExtension(".js");
		r.setGeneratorFqn(frontend.dojo.DojoWidgetJs.class.getName());
		r.setJetPath("/frontend/dojo/widget-js.jsjet");
		r.setMergeStrategy(TemplateMergeStrategy.SIMPLE_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,IDtoType.class,});
		r.setRank(5);
		return r;
	}

	public static ITemplate getTemplate(Tid aTid) {
		if (allTemplates == null) {
			new DojoConstants();
		}
		
		for (ITemplate t : allTemplates) {
			if (t.getName().equals(aTid.name())) {
				return t;
			}
		}
		return null;
	}


}
